package com.tusuo.stds.ui.complete;

import com.hannesdorfmann.mosby.mvp.MvpBasePresenter;
import com.tusuo.stds.MyApp;
import com.tusuo.stds.di.DaggerScope;
import com.tusuo.stds.di.Injector;
import com.tusuo.stds.rest.ApiHelper;
import com.tusuo.stds.rest.CompleteResult;

import javax.inject.Inject;

import autodagger.AutoComponent;
import autodagger.AutoInjector;
import rx.Subscriber;

/**
 * Created by developer on 17-9-28.
 */

@AutoComponent(
        dependencies = MyApp.class
)
@AutoInjector
@DaggerScope(CompleteResultPresenter.class)
public class CompleteResultPresenter extends MvpBasePresenter<CompleteResultView> {

    @Inject
    ApiHelper mApiHelper;

    public CompleteResultPresenter() {
        Injector.initCompleteResultPresenterComponent().inject(this);
    }

    public void loadData(int id) {
        if (id != -1) {
            mApiHelper.getCompleteResult(new GetCompleteResultSubscriber(),id);
        }
    }


    private class GetCompleteResultSubscriber extends Subscriber<CompleteResult> {

        @Override
        public void onCompleted() {

        }

        @Override
        public void onError(Throwable e) {
            System.out.println("error" + e);
        }

        @Override
        public void onNext(CompleteResult completeResult) {
            if (getView() != null && completeResult != null) {
                getView().initView(completeResult);

            }

        }
    }

}
